﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Core;
using KendoMvcUI.Common;
using System.Web.Mvc;

namespace KendoMvcUI.UI
{
    public class Button:KendoUIBase
    {
        public Button(ButtonSettings settings, ViewContext context, IViewDataContainer viewDataContainer)
            : base(settings, context, viewDataContainer)
        { }
        public override string RenderHtml()
        {
            return "<button id='{0}' type='button'>{1}</button>".Formator(Settings.Id,
                ((ButtonSettings)Settings).Text);
        }
    }
    public class ButtonSettings:KendoUIControlSettings
    {
        public ButtonSettings()
            :base("kendoButton")
        { }
        public bool? Enable { get; set; }
        public string Icon { get; set; }
        public string ImageUrl { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript=true)]
        public string Text { get; set; }
        /// <summary>
        /// Defines a CSS class (or multiple classes separated by spaces), 
        /// which will be used for applying a background image to a span element inside the Button. 
        /// In case you want to use an icon from the Kendo UI theme sprite background image, 
        /// it is easier to use the icon property.
        /// </summary>
        public string SpriteCssClass { get; set; }
        [PropertySetting(IsIngoreForJavaScript=true)]
        public string OnClick { get; set; }

        public override string ToJsSettings()
        {
            var jsScript= base.ToJsSettings();
            if(!jsScript.EndsWith(","))
                jsScript+=",";

            if (!OnClick.IsNullOrWhiteSpace())
                jsScript += "click:{0},".Formator(OnClick);

            return jsScript.TrimEnd(',');
        }
    }
}
